#
# @lc app=leetcode.cn id=67 lang=python3
#
# [67] 二进制求和
#

# @lc code=start
class Solution:
    def addBinary(self, a: str, b: str) -> str:
       aIndex = len(a)
       bIndex = len(b)
       diff = aIndex - bIndex
       if diff > 0:
           b = '0' * diff + b
       elif diff < 0:
           a = '0' * (-diff) + a
       
       aIndex = len(a)
       carry = 0
       
       c = ''
       while aIndex > 0:
           temp = int(a[aIndex - 1]) + int(b[aIndex - 1]) + carry
           carry = temp // 2 #获取进位值
           c = str(temp % 2 ) + c
           
           aIndex -= 1 
       if carry == 0:
           return c
       else:
           return "1" + c
                   
           
# @lc code=end

